package com.example.apple.ddhr_new.activity.widget;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;

import com.example.apple.ddhr_new.R;

import androidx.annotation.ColorRes;
import androidx.annotation.Nullable;
//    定义画笔

public class CicleView extends View {
    public CicleView(Context context) {
        super(context);
    }

    @Override
    public void setBackgroundColor(int backgroundColor) {
        this.backgroundColor = backgroundColor;


    }

    public  @ColorRes int backgroundColor ;
    Paint paint;


    @SuppressLint("ResourceAsColor")
    public CicleView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        backgroundColor =  context.getResources().getColor(R.color.red) ;
        invalidate();
    }


    public CicleView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);

    }
    @SuppressLint("ResourceAsColor")
    @Override
    public void draw(Canvas canvas) {
        super.draw(canvas);

//        实例化画笔对象
        paint = new Paint();
//        给画笔设置颜色
        paint.setColor(backgroundColor);
//        设置画笔属性
        paint.setStyle(Paint.Style.FILL);//画笔属性是实心圆

//        paint.setStrokeWidth(1);//设置画笔粗细

        /*四个参数：
                参数一：圆心的x坐标
                参数二：圆心的y坐标
                参数三：圆的半径
                参数四：定义好的画笔
                */
        canvas.drawCircle(getWidth() / 2, getHeight() / 2, getHeight()/2, paint);

    }

}
